<?php print "<?php"; ?>

<?php if($isContentType): ?>

<?php if($supportEntity): ?>
/**
 * Implements hook_entity_info().
 */
function <?php print $machine_name; ?>_entity_info() {
  return array(
    'name' => '<?php print $machine_name; ?>',
    'primaryKey' => '<?php print substr($machine_name, 0, 1 ); ?>id',
    'baseTable'  => '<?php print $machine_name; ?>',
  );
}
<?php endif; ?>

<?php if($supportToken): ?>
/**
 * Implements hook_tokens().
 */
function <?php print $machine_name; ?>_tokens($type, $tokens, array $data = [], array $options = []) {
  $replacements = array();
  if ($type == '<?php print $machine_name; ?>') {
    $<?php print $machine_name; ?> = reset($data);
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case '<?php print substr($machine_name, 0, 1 ); ?>id':
          $replacements[$original] = $<?php print $machine_name; ?>-><?php print substr($machine_name, 0, 1 ); ?>id;
          break;

<?php foreach ($fields as $field): ?>
        case '<?php print $field['name']; ?>':
          $replacements[$original] = $<?php print $machine_name; ?>-><?php print $field['name']; ?>;
          break;
<?php endforeach; ?>

        case 'uid':
          $replacements[$original] = $<?php print $machine_name; ?>->uid;
          break;

        case 'created':
          $replacements[$original] = date("Y-m-d H:i:s", $<?php print $machine_name; ?>->created);
          break;

        case 'updated':
          $replacements[$original] = date("Y-m-d H:i:s", $<?php print $machine_name; ?>->updated);
          break;
      }
    }
  }

  return $replacements;
}
<?php endif; ?>

/**
 * get <?php print $module; ?> by id
 */
function get_<?php print $machine_name; ?>_byid($<?php print substr($machine_name, 0, 1 ); ?>id) {
    $<?php print $machine_name; ?> = db_select('<?php print $machine_name; ?>', '<?php print substr($machine_name, 0, 1 ); ?>')
      ->fields('<?php print substr($machine_name, 0, 1 ); ?>')
      ->condition('<?php print substr($machine_name, 0, 1 ); ?>.<?php print substr($machine_name, 0, 1 ); ?>id', $<?php print substr($machine_name, 0, 1 ); ?>id)
      ->execute()
      ->fetchObject();

    return $<?php print $machine_name; ?>;
}

/**
 * get all <?php print $module; ?>.
 */
function get_all_<?php print $machine_name; ?>($parms) {
    $data = array();
    $query = db_select('<?php print $machine_name; ?>', '<?php print substr($machine_name, 0, 1 ); ?>')
      ->fields('<?php print substr($machine_name, 0, 1 ); ?>')
      ->extend('Pager')->size(20)->page($parms['page'])
      ->orderBy('<?php print substr($machine_name, 0, 1 ); ?>.created', 'DESC');

    $data['pager'] = $query->fetchPager();
    $data['list'] = $query->execute()->fetchAll();

    return $data;
}

<?php endif; ?>
